#ifndef CPP_ANIMATION_H
#define CPP_ANIMATION_H

class View;

typedef enum {
    ANIMATION_TYPE_NONE,
    ANIMATION_TYPE_VISIABLE_CHANGE, //可见性改变
    ANIMATION_TYPE_COUNT
} ANIMATION_TYPE;

typedef enum {
    ANIMATION_EFFECT_NONE,
    ANIMATION_EFFECT_CUSTOM, //自定义
    ANIMATION_EFFECT_RIGHT_LEFT_ZOOM, //右到左的缩放效果
    ANIMATION_EFFECT_COUNT
} ANIMATION_EFFECT;

typedef enum {
    ANIMATION_EFFECT_FLAG_NONE,
    ANIMATION_EFFECT_FLAG_FORWARD, //正向效果
    ANIMATION_EFFECT_FLAG_BACKWARD, //反向效果
    ANIMATION_EFFECT_FLAG_COUNT
} ANIMATION_EFFECT_FLAG;

//@brief 动画
//@author cvte
//@description 用于生成单个动画，并配合AnimationManager实现动画效果
class Animation {
   public:
    class AminationListener {
       public:
        //@method 进入动画开始
        virtual void onAminationStart();
        //@method 进入动画结束
        virtual void onAminationEnd();
        //@method 进入动画过程帧回调，返回的Bitmap最终会绘制到控件位置上
        //@param backgroundBitmap为全屏背景画面，startBitmap为动画开始时的控件画面，endBitmap为动画结束时的控件画面，viewBitmap为控件画面
        virtual Bitmap* onAminationProcess(Bitmap& backgroundBitmap, Bitmap& startBitmap, Bitmap& endBitmap, Bitmap& viewBitmap);
    };

    Animation(View& view, ANIMATION_TYPE type, int targetFlag, ANIMATION_EFFECT effect, ANIMATION_EFFECT_FLAG effectFlag);
    Animation(View& view, ANIMATION_TYPE type, int targetFlag, ANIMATION_EFFECT effect, ANIMATION_EFFECT_FLAG effectFlag, AminationListener* listener);
    virtual ~Animation();
    View* getView();
    //@method 获取View初始化的可见性
    int getViewInitialVisibility();

    //@method 动画准备
    void prepareAnimation();
    //@method 开始动画
    void startAnimation();
    //@method 处理动画帧，如果动画结束返回false，否则返回true
    bool processAnimation(Bitmap& backgroundBitmap);
    //@method 结束动画
    void endAnimation();

   private:
    View* mView = nullptr;
    int mViewInitialVisibility = View::VISIBLE;
    ANIMATION_TYPE mAnimationType;
    int mAnimationTypeFlag = 0;
    ANIMATION_EFFECT mAnimationEffect = ANIMATION_EFFECT_NONE;
    ANIMATION_EFFECT_FLAG mAnimationEffectFlag = ANIMATION_EFFECT_FLAG_NONE;
    Bitmap* mAnimationStartBitmap = nullptr;
    Bitmap* mAnimationEndBitmap = nullptr;
    Bitmap* mAnimationViewBitmap = nullptr; //控件可见时的内容
    int mAnimationFrameIndex = 0;
    AminationListener* mAnimationListener = nullptr;
};

#endif